<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    body {
      height: 2000px;
    }
  </style>
  <body>
    <h1>节流</h1>
    <h1>节流</h1>
    <h1>节流</h1>
    <h1>节流</h1>
    <h1>节流</h1>
  </body>
  <script>
    // function dote(fn,delay){
    //     var time = 0;
    //     return function(){
    //         var nowTime = Date.now()
    //         if(nowTime - time > delay){
    //             fn.apply(this,arguments)
    //             time =nowTime
    //         }
    //     // console.log('hh')
    //     }
    // }
    // document.onscroll = dote(
    //     function(event){
    //     console.log('yunxing')
    //     console.log(this)
    //     console.log(event)
    // },2000)
  
    //节流一般绑定鼠标事件
    function dote(fn,delay){
        var time = 0;  //默认最后shijian
        return function(){
            var timeNow = Date.now()  //当前时间
            if(timeNow - time >= delay){
                fn.apply(this,arguments)
                time =timeNow
            }
            console.log('xixi')
        }
    }
        document.addEventListener('scroll',dote(
            function(){
                console.log('hha')
            },1000))
  </script>
</html>
